package com.sskj.level.presenter;

import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.common.base.HttpData;
import com.sskj.level.bean.TradeListBean;
import com.sskj.level.http.HttpConfig;
import com.sskj.level.ui.fragment.EntrustFragment;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.CallBackOption;
import com.sskj.lib.http.JsonConverter;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Flowable;


public class EntrustFragmentPresenter extends BasePresenter<EntrustFragment> {

    public Flowable<List<TradeListBean>> getData(String code, String pageNum, String pageSize) {
        return httpService.getWeituo(code, pageNum, pageSize)
                .converter(new JsonConverter<HttpData<PageBean<TradeListBean>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(pageBeanHttpData -> pageBeanHttpData.getData().getList())
                .onErrorReturn(throwable -> new ArrayList<>())
                ;
    }


    public void cancelOrder(String orderId) {
        httpService.cancelOrder(orderId)
                .execute(new CallBackOption<HttpData>() {
                }
                        .loadBind(mView)
                        .execute(httpData -> {

                            if (httpData.getStatus() == HttpConfig.OK) {
                                mView.cancelOrderSuccess();
                            }
                        }));
    }


}
